<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>保存邮箱并发送验证邮件 | 美多商城</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../C02-Users/Email/VerifyEmail.html" />
    
    
    <link rel="prev" href="../../C02-Users/Email/DjangoEmail.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="2.14.2"
        data-chapter-title="保存邮箱并发送验证邮件"
        data-filepath="C02-Users/Email/SendEmail.md"
        data-basepath="../.."
        data-revision="Sat Aug 11 2018 20:09:13 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        美多商城
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="C01-Prepare/index.html">
            
                
                    <a href="../../C01-Prepare/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        项目准备
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="C01-Prepare/BusinessModel.html">
            
                
                    <a href="../../C01-Prepare/BusinessModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        商业模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="C01-Prepare/DevelopmentProcess.html">
            
                
                    <a href="../../C01-Prepare/DevelopmentProcess.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        开发流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="C01-Prepare/ProductAnalysis.html">
            
                
                    <a href="../../C01-Prepare/ProductAnalysis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        需求分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="C01-Prepare/ProjectStructure.html">
            
                
                    <a href="../../C01-Prepare/ProjectStructure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        项目架构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="C01-Prepare/StartProject.html">
            
                
                    <a href="../../C01-Prepare/StartProject.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        创建工程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="C01-Prepare/Config.html">
            
                
                    <a href="../../C01-Prepare/Config.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        配置
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="C02-Users/index.html">
            
                
                    <a href="../../C02-Users/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        用户部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="C02-Users/UserModel.html">
            
                
                    <a href="../../C02-Users/UserModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        用户模型类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="C02-Users/RegisterAnalysis.html">
            
                
                    <a href="../../C02-Users/RegisterAnalysis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        注册业务接口分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="C02-Users/ImageCode.html">
            
                
                    <a href="../../C02-Users/ImageCode.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        图片验证码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="C02-Users/SMSCode.html">
            
                
                    <a href="../../C02-Users/SMSCode.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        短信验证码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="C02-Users/CORS.html">
            
                
                    <a href="../../C02-Users/CORS.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        跨域CORS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="C02-Users/CelerySendSMSCode.html">
            
                
                    <a href="../../C02-Users/CelerySendSMSCode.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        使用Celery发送短信
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="C02-Users/AccountExistingCheck.html">
            
                
                    <a href="../../C02-Users/AccountExistingCheck.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        判断帐号是否存在
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="C02-Users/Register.html">
            
                
                    <a href="../../C02-Users/Register.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        注册
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="C02-Users/JWT.html">
            
                
                    <a href="../../C02-Users/JWT.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        JWT
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="C02-Users/DRF-JWT.html">
            
                
                    <a href="../../C02-Users/DRF-JWT.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.</b>
                        
                        Django REST framework JWT
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="C02-Users/Login.html">
            
                
                    <a href="../../C02-Users/Login.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.</b>
                        
                        登录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="C02-Users/QQLogin/index.html">
            
                
                    <a href="../../C02-Users/QQLogin/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.12.</b>
                        
                        QQ登录
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.12.1" data-path="C02-Users/QQLogin/Step1.html">
            
                
                    <a href="../../C02-Users/QQLogin/Step1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.12.1.</b>
                        
                        第一步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.12.2" data-path="C02-Users/QQLogin/Step2.html">
            
                
                    <a href="../../C02-Users/QQLogin/Step2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.12.2.</b>
                        
                        第二步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.12.3" data-path="C02-Users/QQLogin/Step3.html">
            
                
                    <a href="../../C02-Users/QQLogin/Step3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.12.3.</b>
                        
                        第三步
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="C02-Users/UserInfo.html">
            
                
                    <a href="../../C02-Users/UserInfo.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.13.</b>
                        
                        用户中心个人信息
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="C02-Users/Email/index.html">
            
                
                    <a href="../../C02-Users/Email/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.14.</b>
                        
                        邮件与验证
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.14.1" data-path="C02-Users/Email/DjangoEmail.html">
            
                
                    <a href="../../C02-Users/Email/DjangoEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.14.1.</b>
                        
                        Django发送邮件的方法
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="2.14.2" data-path="C02-Users/Email/SendEmail.html">
            
                
                    <a href="../../C02-Users/Email/SendEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.14.2.</b>
                        
                        保存邮箱并发送验证邮件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.14.3" data-path="C02-Users/Email/VerifyEmail.html">
            
                
                    <a href="../../C02-Users/Email/VerifyEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.14.3.</b>
                        
                        验证邮箱链接
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.15" data-path="C02-Users/Address/index.html">
            
                
                    <a href="../../C02-Users/Address/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.15.</b>
                        
                        收货地址
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.15.1" data-path="C02-Users/Address/AreaSelect.html">
            
                
                    <a href="../../C02-Users/Address/AreaSelect.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.15.1.</b>
                        
                        省市区地址查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.15.2" data-path="C02-Users/Address/Cache.html">
            
                
                    <a href="../../C02-Users/Address/Cache.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.15.2.</b>
                        
                        使用缓存
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.15.3" data-path="C02-Users/Address/UserAddressManagement.html">
            
                
                    <a href="../../C02-Users/Address/UserAddressManagement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.15.3.</b>
                        
                        用户地址管理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.15.4" data-path="C02-Users/Address/UserAddressCode.html">
            
                
                    <a href="../../C02-Users/Address/UserAddressCode.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.15.4.</b>
                        
                        用户地址代码
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="C03-Goods/index.html">
            
                
                    <a href="../../C03-Goods/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        商品部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="C03-Goods/DatabaseDesign.html">
            
                
                    <a href="../../C03-Goods/DatabaseDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        数据表设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="C03-Goods/FastDFS.html">
            
                
                    <a href="../../C03-Goods/FastDFS.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        FastDFS分布式文件系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="C03-Goods/Docker/index.html">
            
                
                    <a href="../../C03-Goods/Docker/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        Docker使用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="C03-Goods/Docker/Introduce.html">
            
                
                    <a href="../../C03-Goods/Docker/Introduce.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.1.</b>
                        
                        Docker简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="C03-Goods/Docker/InstallAndOperations.html">
            
                
                    <a href="../../C03-Goods/Docker/InstallAndOperations.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.2.</b>
                        
                        安装与操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="C03-Goods/FastDFSDocker.html">
            
                
                    <a href="../../C03-Goods/FastDFSDocker.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        使用Docker安装FastDFS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="C03-Goods/FastDFSClientAndDjangoFileSystem.html">
            
                
                    <a href="../../C03-Goods/FastDFSClientAndDjangoFileSystem.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        FastDFS客户端与自定义文件存储系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="C03-Goods/CKEditor.html">
            
                
                    <a href="../../C03-Goods/CKEditor.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        CKEditor富文本编辑器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="C03-Goods/ImportGoodsData.html">
            
                
                    <a href="../../C03-Goods/ImportGoodsData.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        添加测试数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="C03-Goods/FreezeHTML.html">
            
                
                    <a href="../../C03-Goods/FreezeHTML.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        页面静态化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="C03-Goods/DjangoCrontab.html">
            
                
                    <a href="../../C03-Goods/DjangoCrontab.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        定时任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="C03-Goods/GenerateIndexHTMLScript.html">
            
                
                    <a href="../../C03-Goods/GenerateIndexHTMLScript.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        静态化首页的手动脚本
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.11" data-path="C03-Goods/GoodsDetail.html">
            
                
                    <a href="../../C03-Goods/GoodsDetail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.11.</b>
                        
                        商品详情页面
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.12" data-path="C03-Goods/UserBrowseHistory.html">
            
                
                    <a href="../../C03-Goods/UserBrowseHistory.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.12.</b>
                        
                        用户浏览历史记录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.13" data-path="C03-Goods/GoodsList.html">
            
                
                    <a href="../../C03-Goods/GoodsList.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.13.</b>
                        
                        商品列表页
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.14" data-path="C03-Goods/GoodsSearch.html">
            
                
                    <a href="../../C03-Goods/GoodsSearch.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.14.</b>
                        
                        商品搜索
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="C04-Cart/index.html">
            
                
                    <a href="../../C04-Cart/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        购物车部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="C04-Cart/DataStructureDesign.html">
            
                
                    <a href="../../C04-Cart/DataStructureDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        购物车数据存储设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="C04-Cart/Add.html">
            
                
                    <a href="../../C04-Cart/Add.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        购物车增加
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="C04-Cart/Query.html">
            
                
                    <a href="../../C04-Cart/Query.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        购物车查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="C04-Cart/Modify.html">
            
                
                    <a href="../../C04-Cart/Modify.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        购物车修改
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="C04-Cart/Delete.html">
            
                
                    <a href="../../C04-Cart/Delete.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        购物车删除
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="C04-Cart/SelectAll.html">
            
                
                    <a href="../../C04-Cart/SelectAll.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        购物车全选
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="C04-Cart/MergeCart.html">
            
                
                    <a href="../../C04-Cart/MergeCart.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        登录合并购物车
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="C05-Order/index.html">
            
                
                    <a href="../../C05-Order/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        订单部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="C05-Order/OrderDBModel.html">
            
                
                    <a href="../../C05-Order/OrderDBModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        订单数据库设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="C05-Order/PlaceOrder.html">
            
                
                    <a href="../../C05-Order/PlaceOrder.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        订单结算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="C05-Order/SaveOrder.html">
            
                
                    <a href="../../C05-Order/SaveOrder.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        保存订单
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="C05-Order/OrderSuccess.html">
            
                
                    <a href="../../C05-Order/OrderSuccess.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        下单成功
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="C06-Pay/index.html">
            
                
                    <a href="../../C06-Pay/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        支付宝支付
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="C06-Pay/Alipay.html">
            
                
                    <a href="../../C06-Pay/Alipay.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        接入支付宝
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="C06-Pay/Paying.html">
            
                
                    <a href="../../C06-Pay/Paying.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        发起支付
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="C06-Pay/PaymentResult.html">
            
                
                    <a href="../../C06-Pay/PaymentResult.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        保存支付结果
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="C07-Xadmin.html">
            
                
                    <a href="../../C07-Xadmin.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        Xadmin
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8" data-path="C08-Permission.html">
            
                
                    <a href="../../C08-Permission.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        用户权限控制
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >美多商城</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x4FDD;&#x5B58;&#x90AE;&#x7BB1;&#x5E76;&#x53D1;&#x9001;&#x9A8C;&#x8BC1;&#x90AE;&#x4EF6;">&#x4FDD;&#x5B58;&#x90AE;&#x7BB1;&#x5E76;&#x53D1;&#x9001;&#x9A8C;&#x8BC1;&#x90AE;&#x4EF6;</h1>
<h4 id="&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;&#xFF1A;">&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;&#xFF1A;</h4>
<p><strong>&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;</strong>&#xFF1A;PUT  <code>/email/</code></p>
<p><strong>&#x8BF7;&#x6C42;&#x53C2;&#x6570;</strong>&#xFF1A; JSON &#x6216; &#x8868;&#x5355;</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x662F;&#x5426;&#x5FC5;&#x987B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>email</td>
<td>str</td>
<td>&#x662F;</td>
<td>Email&#x90AE;&#x7BB1;</td>
</tr>
</tbody>
</table>
<p><strong>&#x8FD4;&#x56DE;&#x6570;&#x636E;</strong>&#xFF1A; JSON</p>
<table>
<thead>
<tr>
<th>&#x8FD4;&#x56DE;&#x503C;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x662F;&#x5426;&#x5FC5;&#x987B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>id</td>
<td>int</td>
<td>&#x662F;</td>
<td>&#x7528;&#x6237;id</td>
</tr>
<tr>
<td>email</td>
<td>str</td>
<td>&#x662F;</td>
<td>Email&#x90AE;&#x7BB1;</td>
</tr>
</tbody>
</table>
<p>&#x5728;users/serializers.py&#x4E2D;&#x65B0;&#x5EFA;&#x5E8F;&#x5217;&#x5316;&#x5668;&#xFF0C;&#x7528;&#x6237;&#x9A8C;&#x8BC1;&#x7528;&#x6237;&#x63D0;&#x4EA4;&#x7684;&#x90AE;&#x7BB1;&#x4FE1;&#x606F;&#x3002;</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EmailSerializer</span><span class="hljs-params">(serializers.ModelSerializer)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x90AE;&#x7BB1;&#x5E8F;&#x5217;&#x5316;&#x5668;
    &quot;&quot;&quot;</span>
    <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Meta</span>:</span>
        model = User
        fields = (<span class="hljs-string">&apos;id&apos;</span>, <span class="hljs-string">&apos;email&apos;</span>)
        extra_kwargs = {
            <span class="hljs-string">&apos;email&apos;</span>: {
                <span class="hljs-string">&apos;required&apos;</span>: <span class="hljs-keyword">True</span>
            }
        }

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">update</span><span class="hljs-params">(self, instance, validated_data)</span>:</span>
        instance.email = validated_data[<span class="hljs-string">&apos;email&apos;</span>]
        instance.save()
        <span class="hljs-keyword">return</span> instance
</code></pre>
<p>&#x5728;users/views.py&#x4E2D;&#x521B;&#x5EFA;&#x65B0;&#x89C6;&#x56FE;&#xFF0C;&#x7528;&#x4E8E;&#x4FDD;&#x5B58;&#x7528;&#x6237;&#x7684;&#x90AE;&#x7BB1;&#x4FE1;&#x606F;&#xFF0C;&#x6CE8;&#x610F;&#x9700;&#x8981;&#x7528;&#x6237;&#x767B;&#x5F55;&#x901A;&#x8FC7;&#x8BA4;&#x8BC1;&#x540E;&#x3002;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> rest_framework.permissions <span class="hljs-keyword">import</span> IsAuthenticated

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EmailView</span><span class="hljs-params">(UpdateAPIView)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x4FDD;&#x5B58;&#x7528;&#x6237;&#x90AE;&#x7BB1;
    &quot;&quot;&quot;</span>
    permission_classes = [IsAuthenticated]
    serializer_class = serializers.EmailSerializer

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_object</span><span class="hljs-params">(self, *args, **kwargs)</span>:</span>
        <span class="hljs-keyword">return</span> self.request.user
</code></pre>
<p>&#x8BBE;&#x7F6E;&#x8DEF;&#x7531;&#x4FE1;&#x606F;</p>
<pre><code class="lang-python"> url(<span class="hljs-string">r&apos;^emails/$&apos;</span>, views.EmailView.as_view()),  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x90AE;&#x7BB1;</span>
</code></pre>
<h3 id="&#x8865;&#x5145;&#x53D1;&#x9001;&#x9A8C;&#x8BC1;&#x90AE;&#x4EF6;">&#x8865;&#x5145;&#x53D1;&#x9001;&#x9A8C;&#x8BC1;&#x90AE;&#x4EF6;</h3>
<p>&#x5728;&#x4FDD;&#x5B58;&#x90AE;&#x7BB1;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x9700;&#x8981;&#x5411;&#x7528;&#x6237;&#x53D1;&#x9001;&#x9A8C;&#x8BC1;&#x90AE;&#x4EF6;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x53D1;&#x9001;&#x90AE;&#x4EF6;&#x7684;&#x5DE5;&#x4F5C;&#x653E;&#x5230;celery&#x4E2D;&#x5F02;&#x6B65;&#x6267;&#x884C;&#x3002;</p>
<p>&#x5728;celery<em>tasks&#x76EE;&#x5F55;&#x4E2D;&#x65B0;&#x5EFA;email&#x76EE;&#x5F55;&#x548C;`email/<em>_init</em></em>.py<code>&#x6587;&#x4EF6;&#x548C;</code>email/tasks.py`&#x6587;&#x4EF6;</p>
<p>&#x5728;<code>email/tasks.py</code>&#x6587;&#x4EF6;&#x4E2D;&#x662F;&#x5B9E;&#x73B0;&#x53D1;&#x9001;&#x90AE;&#x4EF6;&#x7684;&#x5F02;&#x6B65;&#x4EFB;&#x52A1;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> celery_tasks.main <span class="hljs-keyword">import</span> celery_app
<span class="hljs-keyword">from</span> django.core.mail <span class="hljs-keyword">import</span> send_mail
<span class="hljs-keyword">from</span> django.conf <span class="hljs-keyword">import</span> settings


<span class="hljs-decorator">@celery_app.task(name=&apos;send_verify_email&apos;)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">send_verify_email</span><span class="hljs-params">(to_email, verify_url)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x53D1;&#x9001;&#x9A8C;&#x8BC1;&#x90AE;&#x7BB1;&#x90AE;&#x4EF6;
    :param to_email: &#x6536;&#x4EF6;&#x4EBA;&#x90AE;&#x7BB1;
    :param verify_url: &#x9A8C;&#x8BC1;&#x94FE;&#x63A5;
    :return: None
    &quot;&quot;&quot;</span>
    subject = <span class="hljs-string">&quot;&#x7F8E;&#x591A;&#x5546;&#x57CE;&#x90AE;&#x7BB1;&#x9A8C;&#x8BC1;&quot;</span>
    html_message = <span class="hljs-string">&apos;&lt;p&gt;&#x5C0A;&#x656C;&#x7684;&#x7528;&#x6237;&#x60A8;&#x597D;&#xFF01;&lt;/p&gt;&apos;</span> \
                   <span class="hljs-string">&apos;&lt;p&gt;&#x611F;&#x8C22;&#x60A8;&#x4F7F;&#x7528;&#x7F8E;&#x591A;&#x5546;&#x57CE;&#x3002;&lt;/p&gt;&apos;</span> \
                   <span class="hljs-string">&apos;&lt;p&gt;&#x60A8;&#x7684;&#x90AE;&#x7BB1;&#x4E3A;&#xFF1A;%s &#x3002;&#x8BF7;&#x70B9;&#x51FB;&#x6B64;&#x94FE;&#x63A5;&#x6FC0;&#x6D3B;&#x60A8;&#x7684;&#x90AE;&#x7BB1;&#xFF1A;&lt;/p&gt;&apos;</span> \
                   <span class="hljs-string">&apos;&lt;p&gt;&lt;a href=&quot;%s&quot;&gt;%s&lt;a&gt;&lt;/p&gt;&apos;</span> % (to_email, verify_url, verify_url)
    send_mail(subject, <span class="hljs-string">&quot;&quot;</span>, settings.EMAIL_FROM, [to_email], html_message=html_message)
</code></pre>
<h5 id="&#x6CE8;&#x610F;">&#x6CE8;&#x610F;</h5>
<p>&#x5728;&#x53D1;&#x9001;&#x90AE;&#x4EF6;&#x7684;&#x5F02;&#x6B65;&#x4EFB;&#x52A1;&#x4E2D;&#xFF0C;&#x9700;&#x8981;&#x7528;&#x5230;django&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x4FEE;&#x6539;celery&#x7684;&#x542F;&#x52A8;&#x6587;&#x4EF6;main.py&#xFF0C;&#x5728;&#x5176;&#x4E2D;&#x6307;&#x660E;celery&#x53EF;&#x4EE5;&#x8BFB;&#x53D6;&#x7684;django&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#xFF0C;&#x5E76;&#x4E14;&#x6CE8;&#x518C;&#x6DFB;&#x52A0;email&#x7684;&#x4EFB;&#x52A1;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> celery <span class="hljs-keyword">import</span> Celery

<span class="hljs-comment"># &#x4E3A;celery&#x4F7F;&#x7528;django&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x8FDB;&#x884C;&#x8BBE;&#x7F6E;</span>
<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> os.getenv(<span class="hljs-string">&apos;DJANGO_SETTINGS_MODULE&apos;</span>):
    os.environ[<span class="hljs-string">&apos;DJANGO_SETTINGS_MODULE&apos;</span>] = <span class="hljs-string">&apos;meiduo_mall.settings.dev&apos;</span>

<span class="hljs-comment"># &#x521B;&#x5EFA;celery&#x5E94;&#x7528;</span>
celery_app = Celery(<span class="hljs-string">&apos;meiduo&apos;</span>)

<span class="hljs-comment"># &#x5BFC;&#x5165;celery&#x914D;&#x7F6E;</span>
celery_app.config_from_object(<span class="hljs-string">&apos;celery_tasks.config&apos;</span>)

<span class="hljs-comment"># &#x81EA;&#x52A8;&#x6CE8;&#x518C;celery&#x4EFB;&#x52A1;</span>
celery_app.autodiscover_tasks([<span class="hljs-string">&apos;celery_tasks.sms&apos;</span>, <span class="hljs-string">&apos;celery_tasks.email&apos;</span>])
</code></pre>
<h5 id="&#x5728;user&#x6A21;&#x578B;&#x7C7B;&#x4E2D;&#x5B9A;&#x4E49;&#x751F;&#x6210;&#x9A8C;&#x8BC1;&#x90AE;&#x7BB1;&#x94FE;&#x63A5;&#x7684;&#x65B9;&#x6CD5;">&#x5728;User&#x6A21;&#x578B;&#x7C7B;&#x4E2D;&#x5B9A;&#x4E49;&#x751F;&#x6210;&#x9A8C;&#x8BC1;&#x90AE;&#x7BB1;&#x94FE;&#x63A5;&#x7684;&#x65B9;&#x6CD5;</h5>
<p>&#x90AE;&#x7BB1;&#x7684;&#x6FC0;&#x6D3B;&#x94FE;&#x63A5;&#x662F;&#x7528;&#x6237;&#x70B9;&#x51FB;&#x65F6;&#x4F1A;&#x8BBF;&#x95EE;&#x7684;&#x7F51;&#x5740;&#xFF0C;&#x6211;&#x4EEC;&#x8BA9;&#x7528;&#x6237;&#x70B9;&#x51FB;&#x65F6;&#x8FDB;&#x5165;&#x5230;success_verify_email.html&#x9875;&#x9762;&#x3002;</p>
<pre><code class="lang-python">    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">generate_verify_email_url</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x751F;&#x6210;&#x9A8C;&#x8BC1;&#x90AE;&#x7BB1;&#x7684;url
        &quot;&quot;&quot;</span>
        serializer = TJWSSerializer(settings.SECRET_KEY, expires_in=constants.VERIFY_EMAIL_TOKEN_EXPIRES)
        data = {<span class="hljs-string">&apos;user_id&apos;</span>: self.id, <span class="hljs-string">&apos;email&apos;</span>: self.email}
        token = serializer.dumps(data).decode()
        verify_url = <span class="hljs-string">&apos;http://www.meiduo.site:8080/success_verify_email.html?token=&apos;</span> + token
        <span class="hljs-keyword">return</span> verify_url
</code></pre>
<h5 id="&#x4FEE;&#x6539;emailserializer&#x5E8F;&#x5217;&#x5316;&#x5668;&#x7684;update&#x65B9;&#x6CD5;&#xFF0C;&#x589E;&#x52A0;&#x53D1;&#x9001;&#x90AE;&#x4EF6;">&#x4FEE;&#x6539;EmailSerializer&#x5E8F;&#x5217;&#x5316;&#x5668;&#x7684;update&#x65B9;&#x6CD5;&#xFF0C;&#x589E;&#x52A0;&#x53D1;&#x9001;&#x90AE;&#x4EF6;</h5>
<pre><code class="lang-python">    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">update</span><span class="hljs-params">(self, instance, validated_data)</span>:</span>
        email = validated_data[<span class="hljs-string">&apos;email&apos;</span>]
        instance.email = email
        instance.save()

        <span class="hljs-comment"># &#x751F;&#x6210;&#x9A8C;&#x8BC1;&#x94FE;&#x63A5;</span>
        verify_url = instance.generate_verify_email_url()
        <span class="hljs-comment"># &#x53D1;&#x9001;&#x9A8C;&#x8BC1;&#x90AE;&#x4EF6;</span>
        send_verify_email.delay(email, verify_url)
        <span class="hljs-keyword">return</span> instance
</code></pre>
<h3 id="&#x524D;&#x7AEF;">&#x524D;&#x7AEF;</h3>
<p>&#x4FEE;&#x6539;user_center_info.js&#x6587;&#x4EF6;&#xFF0C;&#x589E;&#x52A0;save_email&#x65B9;&#x6CD5;</p>
<pre><code class="lang-html">        // &#x4FDD;&#x5B58;email
        save_email: function(){
            var re = /^[a-z0-9][\w\.\-]*@[a-z0-9\-]+(\.[a-z]{2,5}){1,2}$/;
            if(re.test(this.email)) {
                this.email_error = false;
            } else {
                this.email_error = true;
                return;
            }
            axios.put(this.host + &apos;/email/&apos;,
                { email: this.email },
                {
                    headers: {
                        &apos;Authorization&apos;: &apos;JWT &apos; + this.token
                    },
                    responseType: &apos;json&apos;
                })
                .then(response =&gt; {
                    this.set_email = false;
                    this.send_email_btn_disabled = true;
                    this.send_email_tip = &apos;&#x5DF2;&#x53D1;&#x9001;&#x9A8C;&#x8BC1;&#x90AE;&#x4EF6;&apos;
                })
                .catch(error =&gt; {
                    alert(error.data);
                });
        }
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../C02-Users/Email/DjangoEmail.html" class="navigation navigation-prev " aria-label="Previous page: Django发送邮件的方法"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../C02-Users/Email/VerifyEmail.html" class="navigation navigation-next " aria-label="Next page: 验证邮箱链接"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
